using System;
using System.Collections;
using System.Collections.Generic;
using Infragistics.UltraChart.Resources.Appearance;

namespace PluginFrame
{
	public class AxisProperty
	{
		protected AxisAppearance mAxisAppearance;

		protected double mDefaultMax;

		protected double mDefaultMin;

		protected double mDefaultTickInterval;

		protected double mCurrentMax;

		protected double mCurrentMin;

		protected double mTickInterval;

		protected int mTickCount;

		protected double mAutoUpdatePoint;

		protected double mAutoUpdateStartPosition;

		protected double mSreenAutoUpdateRate = 1.0;

		protected double mScreenAutoUpdateStartPositionRate = 1.0;

		protected double mScreenInterval;

		protected double mScreenDefaultInterval;

		protected bool mIsLogAxis;

		protected bool mIsDateTimeAxis;

		protected int mIntegralBits;

		protected int mFractionalBits;

		protected DateTime mStartTime;

		protected bool mIsZoomEnable;

		protected bool mIsZeroAlignment;

		protected bool mIsMaxLimitRange;

		protected bool mIsMinLimitRange;

		protected bool mIsRefreshAsDefault;

		protected bool mIsInitialValue;

		protected Dictionary<double, double> mAccelInc;

		protected Dictionary<double, double> mIncDec;

		protected Dictionary<double, string> mLabelFormat;

		public bool IsRefreshAsDefault
		{
			get
			{
				return mIsRefreshAsDefault;
			}
			set
			{
				mIsRefreshAsDefault = value;
			}
		}

		public bool IsInitialValue
		{
			get
			{
				return mIsInitialValue;
			}
			set
			{
				mIsInitialValue = value;
			}
		}

		public AxisAppearance AxisAppearance
		{
			get
			{
				return mAxisAppearance;
			}
			set
			{
				mAxisAppearance = value;
			}
		}

		public double DefaultTickInterval
		{
			get
			{
				return mDefaultTickInterval;
			}
			set
			{
				mDefaultTickInterval = value;
			}
		}

		public int TickCount
		{
			get
			{
				return mTickCount;
			}
			set
			{
				mTickCount = value;
			}
		}

		public Dictionary<double, double> AccelInc
		{
			get
			{
				return mAccelInc;
			}
			set
			{
				mAccelInc = value;
			}
		}

		public Dictionary<double, double> IncDec
		{
			get
			{
				return mIncDec;
			}
			set
			{
				mIncDec = value;
			}
		}

		public Dictionary<double, string> LabelFormat
		{
			get
			{
				return mLabelFormat;
			}
			set
			{
				mLabelFormat = value;
			}
		}

		public bool IsZeroAlignment
		{
			get
			{
				return mIsZeroAlignment;
			}
			set
			{
				mIsZeroAlignment = value;
			}
		}

		public bool IsMaxLimitRange
		{
			get
			{
				return mIsMaxLimitRange;
			}
			set
			{
				mIsMaxLimitRange = value;
			}
		}

		public bool IsMinLimitRange
		{
			get
			{
				return mIsMinLimitRange;
			}
			set
			{
				mIsMinLimitRange = value;
			}
		}

		public virtual bool IsZoomEnable
		{
			get
			{
				return mIsZoomEnable;
			}
			set
			{
				mIsZoomEnable = value;
			}
		}

		public double TickInterval
		{
			get
			{
				return mTickInterval;
			}
			set
			{
				mTickInterval = value;
			}
		}

		public DateTime StartTime
		{
			get
			{
				return mStartTime;
			}
			set
			{
				mStartTime = value;
			}
		}

		public bool IsLogAxis
		{
			get
			{
				return mIsLogAxis;
			}
			set
			{
				mIsLogAxis = value;
			}
		}

		public bool IsDateTimeAxis
		{
			get
			{
				return mIsDateTimeAxis;
			}
			set
			{
				mIsDateTimeAxis = value;
			}
		}

		public int IntegralBits
		{
			get
			{
				return mIntegralBits;
			}
			set
			{
				mIntegralBits = value;
			}
		}

		public int FractionalBits
		{
			get
			{
				return mFractionalBits;
			}
			set
			{
				mFractionalBits = value;
			}
		}

		public double ScreenDefaultInterval
		{
			get
			{
				return mScreenDefaultInterval;
			}
			set
			{
				mScreenDefaultInterval = value;
			}
		}

		public double ScreenInterval
		{
			get
			{
				return mScreenInterval;
			}
			set
			{
				mScreenInterval = value;
			}
		}

		public double AutoUpdatePoint
		{
			get
			{
				return mAutoUpdatePoint;
			}
			set
			{
				mAutoUpdatePoint = value;
			}
		}

		public double AutoUpdateStartPosition
		{
			get
			{
				return mAutoUpdateStartPosition;
			}
			set
			{
				mAutoUpdateStartPosition = value;
			}
		}

		public double DefaultMax
		{
			get
			{
				return mDefaultMax;
			}
		}

		public double DefaultMin
		{
			get
			{
				return mDefaultMin;
			}
		}

		public double CurrentMax
		{
			get
			{
				return mCurrentMax;
			}
		}

		public double CurrentMin
		{
			get
			{
				return mCurrentMin;
			}
		}

		public event EventHandler AfterScreenIntervalUpdate;

		protected virtual void OnAfterScreenIntervalUpdate(EventArgs e)
		{
			if (this.AfterScreenIntervalUpdate != null)
			{
				this.AfterScreenIntervalUpdate(this, e);
			}
		}

		private object GetDictionarySearchValue<T>(Dictionary<double, T> valueDictionary, T defaultValue, double keyValue)
		{
			if (valueDictionary == null)
			{
				return defaultValue;
			}
			IEnumerator enumerator = valueDictionary.Keys.GetEnumerator();
			while (enumerator.MoveNext())
			{
				double num = (double)enumerator.Current;
				if (keyValue >= num)
				{
					return valueDictionary[num];
				}
			}
			return 1;
		}

		public virtual int DecimalPlaces(double keyValue)
		{
			if (!mIsDateTimeAxis)
			{
				string formatString = GetFormatString(keyValue);
				string[] array = formatString.Split(new string[1] { "." }, StringSplitOptions.None);
				if (array != null && array.Length > 1)
				{
					return array[1].Length;
				}
			}
			return 0;
		}

		public virtual string GetFormatString(double keyValue)
		{
			if (mIsDateTimeAxis)
			{
				return "hh:nn:ss";
			}
			string text = ".".PadRight(mFractionalBits + 1, '0');
			text = text.PadLeft(mIntegralBits + 1, '0');
			string text2 = (string)GetDictionarySearchValue(mLabelFormat, text, keyValue);
			if (text2 == null)
			{
				text2 = text;
			}
			return text2;
		}

		public virtual object GetIncDec(double keyValue)
		{
			if (mIsDateTimeAxis)
			{
				return "0:0:1";
			}
			return GetDictionarySearchValue(mIncDec, 1.0, keyValue);
		}

		public virtual object GetAccelInc(double keyValue)
		{
			if (mIsDateTimeAxis)
			{
				return "0:1:0";
			}
			return GetDictionarySearchValue(mAccelInc, 5.0, keyValue);
		}

		public virtual bool SetAxisDefaultRange(double minValue, double maxValue)
		{
			mDefaultMax = maxValue;
			mDefaultMin = minValue;
			return true;
		}

		public virtual bool SetAxisCurrentRange(double minValue, double maxValue)
		{
			mCurrentMax = maxValue;
			mCurrentMin = minValue;
			return true;
		}

		public virtual DateTime GetDateTimeFromValue(double value)
		{
			return mStartTime.AddSeconds(value);
		}

		public virtual void UpdateAxisDefaultRange(bool updateCurrentRange)
		{
			mDefaultMin = mAutoUpdateStartPosition;
			mDefaultMax = mScreenInterval + mDefaultMin;
			if (updateCurrentRange)
			{
				mCurrentMin = mDefaultMin;
				mCurrentMax = mDefaultMax;
			}
		}

		public virtual void UpdateAxisAutoUpdatePoint(double screenAutoUpdateRate, double screenAutoUpdateStartPositionRate)
		{
			mAutoUpdatePoint = mDefaultMin + (mDefaultMax - mDefaultMin) * screenAutoUpdateRate;
			mAutoUpdateStartPosition = mDefaultMin + mScreenInterval * screenAutoUpdateStartPositionRate;
			mSreenAutoUpdateRate = screenAutoUpdateRate;
			mScreenAutoUpdateStartPositionRate = screenAutoUpdateStartPositionRate;
		}

		public virtual void UpdateScreenInterval()
		{
			mScreenInterval = mCurrentMax - mCurrentMin;
			mDefaultMin = mDefaultMax - mScreenInterval;
			UpdateAxisAutoUpdatePoint(mSreenAutoUpdateRate, mScreenAutoUpdateStartPositionRate);
			OnAfterScreenIntervalUpdate(new EventArgs());
		}

		public virtual int GetScrollBarMaxPosition()
		{
			return (int)(mDefaultMax - mScreenInterval) + 1;
		}

		public virtual bool CalculateZeroAligmentRange(ref double min, ref double max, ref double interval, int intervalCount, bool isMaxChange, bool isZeroAlignment)
		{
			double num = 0.0;
			double num2 = 0.0;
			if (max <= min)
			{
				return false;
			}
			bool flag = !isZeroAlignment || min * max >= 0.0;
			interval = Math.Round((max - min) / (double)intervalCount, 6);
			if (flag)
			{
				if ((!(min >= 0.0) || !(max >= 0.0)) && (!(min < 0.0) || !(max >= 0.0)) && min <= 0.0 && !(max <= 0.0))
				{
				}
			}
			else
			{
				num = Math.Abs(max);
				num2 = Math.Abs(min);
				if (isMaxChange)
				{
					int num3 = (int)Math.Round(num / interval);
					if (intervalCount <= num3)
					{
						interval = num2;
						return false;
					}
					interval = num2 / (double)(intervalCount - num3);
					max = (double)num3 * interval;
				}
				else
				{
					int num4 = (int)Math.Round(num2 / interval);
					if (intervalCount <= num4)
					{
						interval = num;
						return false;
					}
					interval = num / (double)(intervalCount - num4);
					min = (double)(-1 * num4) * interval;
				}
			}
			return true;
		}
	}
}
